package pl.poznan.put.cs.idss.students.coolring.ui.components;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

//TODO wszystkie stałe do properties

public class ColorPickerDialog extends JFrame implements ChangeListener,
		WindowListener {

	private static final long serialVersionUID = 3136258721828758798L;

	private JColorChooser chooser;
	private ColorPicker parentPicker;

	public ColorPickerDialog(ColorPicker parentPicker) {

		addWindowListener(this);

		this.parentPicker = parentPicker;
		chooser = new JColorChooser(parentPicker.getCurrentColor());
		chooser.setPreviewPanel(new JPanel());
		AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[1];
		for (AbstractColorChooserPanel panel : chooser.getChooserPanels()) {
			if (panel.getDisplayName().equals("RGB")) {
				newPanels[0] = panel;
			}
		}
		chooser.setChooserPanels(newPanels);
		setTitle("ColorPickerDialog.class");
		setSize(600, 300);
		setVisible(true);
		add(chooser);
		chooser.getSelectionModel().addChangeListener(this);

	}

	public void stateChanged(ChangeEvent e) {
		parentPicker.setCurrentColor(chooser.getColor());
		parentPicker.repaint();
	}

	public void windowOpened(WindowEvent e) {
	}

	public void windowClosing(WindowEvent e) {
		parentPicker.addAsLastColor(chooser.getColor());
	}

	public void windowClosed(WindowEvent e) {
	}

	public void windowIconified(WindowEvent e) {
	}

	public void windowDeiconified(WindowEvent e) {
	}

	public void windowActivated(WindowEvent e) {
	}

	public void windowDeactivated(WindowEvent e) {
	}

}
